package me.dqn.filter;

import me.dqn.annotation.PointCut;
import me.dqn.aspect.ProxyAspect;
import net.sf.cglib.proxy.CallbackFilter;

import java.lang.reflect.Method;

/**
 * @author dqn
 * 2018/5/12--16:39
 * 根据被增强方法的注解来区分使用的callback下标
 */
public class EnhanceFilter implements CallbackFilter {
    @Override
    public int accept(Method method) {
        if (method.isAnnotationPresent(PointCut.class)) {
            String type = method.getAnnotation(PointCut.class).type();
            if (type.equals(ProxyAspect.BEFORE)) {
                return 0;
            } else if (type.equals(ProxyAspect.AFTER)) {
                return 1;
            } else if (type.equals(ProxyAspect.AROUND)) {
                return 2;
            }
        }
        return 0;
    }

    @Override
    public boolean equals(Object o) {
        return false;
    }
}
